<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('商城订单列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId" action="">
					<input type="hidden" id="status" name="status" /> <input
						type="hidden" id="delFlag" name="delFlag" value="0" />
					<div class="tabs-container">
						<ul class="nav nav-tabs">
							<li class="active"><a data-toggle="tab" href="#tab-0"
								id="tab-0" onclick="query('',0)">全部</a></li>
							<li class=""><a data-toggle="tab" href="#tab-1"
								onclick="query(1,0)" id="tab-1"><span class="nav-label">待付款</span><span
									class="label label-danger pull-right" id="payCount"></span></a></li>
							<li class=""><a data-toggle="tab" href="#tab-2"
								onclick="query(2,0)" id="tab-2"><span class="nav-label">待发货</span><span
									class="label label-danger pull-right" id="deliveryCount"></span></a></li>
							<li class=""><a data-toggle="tab" href="#tab-3"
								onclick="query(3,0)" id="tab-3"><span class="nav-label">待收货</span><span
									class="label label-danger pull-right" id="rogCount"></span></a></li>
							<li class=""><a data-toggle="tab" href="#tab-5"
								onclick="query(4,0)" id="tab-4"><span class="nav-label">已完成</span><span
									class="label pull-right" id="finishCount"></span></a></li>
							<li class=""><a data-toggle="tab" href="#tab-6"
								onclick="query(-1,0)" id="tab-5"><span class="nav-label">已关闭</span><span
									class="label label-danger pull-right" id="cancelCount"></span></a></li>
							<li class=""><a data-toggle="tab" href="#tab-8"
								onclick="query('',2)" id="tab-7"><span class="nav-label">已删除</span><span
									class="label label-danger pull-right" id="deleteCount"></span></a></li>
						</ul>
					</div>
					<div class="select-list">
						<ul>
							<li><label>订单编号：</label> <input type="text" name="orderNo" />
							</li>
							<li><label>会员ID：</label> <input type="text" name="memberId" />
							</li>
							<li><label>支付时间：</label> <input type="text"
								class="time-input" placeholder="请选择支付时间" name="payTime" /></li>
							<li><a class="btn btn-primary btn-rounded btn-sm"
								onclick="query('',0)"><i class="fa fa-search"></i>&nbsp;搜索</a> <a
								class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
									class="fa fa-refresh"></i>&nbsp;重置</a></li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()"
					shiro:hasPermission="shop:order:add"> <i class="fa fa-plus"></i>
					添加
				</a> <a class="btn btn-danger multiple disabled"
					onclick="$.operate.removeAll()"
					shiro:hasPermission="shop:order:remove"> <i
					class="fa fa-remove"></i> 删除
				</a> <a class="btn btn-warning" onclick="$.table.exportExcel()"
					shiro:hasPermission="shop:order:export"> <i
					class="fa fa-download"></i> 导出
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript" type="text/javascript">
        var prefix = ctx + "shop/trade/order";
    	var orderTypes = [[${@dict.getType('shop_order_type')}]];
    	var deliveryTypes = [[${@dict.getType('shop_delivery_type')}]];
    	var payTypes = [[${@dict.getType('shop_pay_type')}]];
    	var datas = [[${@dict.getType('shop_order_status')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                modalName: "商城订单",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'orderId',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '订单号',
                    align: 'center'
                },
                {
                    field: 'orderType',
                    title: '订单类型',
                    align: 'center',
                   	formatter: function(value, item, index) {
    		            	return $.table.selectDictLabel(orderTypes,value);
   		            }
                },
                {
                    field: 'contact',
                    title: '收货人',
                    align: 'center'
                },   
                {
                    field: 'deliveryType',
                    title: '配送方式',
                    align: 'center',
                    formatter: function(value, item, index) {
 		            	return $.table.selectDictLabel(deliveryTypes,value);
 		            }
                },
                {
                    field: 'payAmount',
                    title: '实付金额',
                    align: 'center'
                },   
                {
                    field: 'payType',
                    title: '支付方式',
                    align: 'center',
                  	formatter: function(value, item, index) {
						if ($.common.isNotEmpty(value)) {
					    	 return $.table.selectDictLabel(payTypes,value);
					    }
					    return '暂未支付';
    		        }
                },    
                {
                    field: 'status',
                    title: '订单状态',
                    align: 'center',
 		            formatter: function(value, item, index) {
 		                if(item.delFlag == 0){
 		            	  return $.table.selectDictLabel(datas,value);
 		                }
 		                return '<span class="badge badge-inverse">已删除</span>'
 		            }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.orderId + '\',1300,800)"><i class="fa fa-search"></i>详细</a> ');
                        var more = [];
                        if(row.status==1){
						  actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="payOrder(\'' + row.orderId + '\')">立即付款</a> ');
                        }
                        else if(row.status==2){
                           actions.push("<a class='btn btn-success btn-xs' href='javascript:void(0)' onclick='deliveryOrder(" + row.orderId + ")'>立即发货</a> ");
                           more.push("<a class='btn btn-primary btn-xs' href='javascript:void(0)' onclick='remarkOrder(" + row.orderId + ")'>备注</a> ");
                        }
                        else if(row.status==3){
                           actions.push("<a class='btn btn-success btn-xs' href='javascript:void(0)' onclick='monitorOrder(" + row.orderId + ")'>查看物流</a> ");
                           more.push("<a class='btn btn-primary btn-xs' href='javascript:void(0)' onclick='remarkOrder(" + row.orderId + ")'>备注</a> ");
                        }
                        else if(row.status==4){
						   more.push("<a class='btn btn-primary btn-xs' href='javascript:void(0)' onclick='remarkOrder(" + row.orderId + ")'>备注</a> ");
                           more.push("<a class='btn btn-danger  btn-xs' href='javascript:void(0)' onclick='deleteOrder(" + row.orderId + ")'>删除订单</a> ");
                        }
		                actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
		                return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            
            refreshCount();
        });
        //查询
        function query(status,delFlag){
        	$("#status").val(status);
        	$("#delFlag").val(delFlag);
        	$.table.search();
        	refreshCount();
        }
        //重置
        function reset(){
        	$("#delFlag").val("");
        	$("#tab-0").click();
        	refreshCount();
        }
        //刷新数量
        function refreshCount(){
        	$.ajax({
   	            url: prefix + "/statusCount",
   	            type: "get",
   	            success: function(res) {
   	            	if(res.data.payCount==0){
   	            		$("#payCount").text("");
   	            	}else{
   	            		$("#payCount").text(res.data.payCount);
   	            	}
   	            	if(res.data.deliveryCount==0){
   	            		$("#deliveryCount").text("");
   	            	}else{
   	            		$("#deliveryCount").text(res.data.deliveryCount);
   	            	}
   	            	if(res.data.rogCount==0){
   	            		$("#rogCount").text("");
   	            	}else{
   	            		$("#rogCount").text(res.data.rogCount);
   	            	}
   	            	if(res.data.finishCount==0){
   	            		$("#finishCount").text("");
   	            	}else{
   	            		$("#finishCount").text(res.data.finishCount);
   	            	}
   	            	if(res.data.closeCount==0){
   	            		$("#closeCount").text("");
   	            	}else{
   	            		$("#closeCount").text(res.data.closeCount);
   	            	}
   	            }
   	        })
        }
        
      //立即付款
        function payOrder(orderId){
        	$.modal.confirm("确认要修改立即支付吗?修改后订单状态将无法恢复,请谨慎操作!", function() {
        		$.ajax({
       	            url: prefix + "/pay/"+orderId,
       	            type: "post",
       	            success: function(result) {
       	            	if (result.code == web_status.SUCCESS) {
       	            		layer.msg("操作成功,正在刷新数据请稍后……", {
       		            	    icon: 1,
       		            	    time: 500,
       		            	    shade: [0.1, '#8F8F8F']
       		            	},function() {
       		            		location.reload();
       		            	});
       	            	} else {
       	            		alert(result.msg);
       	            	}
       	            }
       	        })
	    	});
        }
        //订单发货
    	function deliveryOrder(orderId) {
		    var url = prefix + "/delivery/"+orderId;
		    $.modal.open("发货", url, '800', '500');
		}
    	  //备注订单
    	function remarkOrder(orderId) {
    		 layer.prompt({title: '添加备注', formType: 2,maxlength: 200}, function(itemName, index){
    			 $.ajax({
        	            url: prefix + "/remark",
        	            type: "post",
        	            data:{orderId:orderId,remark:itemName},
        	            success: function(result) {
        	            	if (result.code == web_status.SUCCESS) {
        	            		   layer.close(index);
        	            	} else {
        	            		alert(result.msg);
        	            	}
        	            }
        	        })
 	  	   });
		}
    </script>
</body>
</html>